import requests
from lxml import etree
url = 'https://www.che168.com/china/list/'
response = requests.get(url)
print(response.status_code)
html = response.text
ehtml = etree.HTML(html)
dealerid = ehtml.xpath("//ul[@class='viewlist_ul']/li/@dealerid")
infoid = ehtml.xpath("//ul[@class='viewlist_ul']/li/@infoid")
for i in range(len(dealerid)):
    url1 = ("https://www.che168.com/dealer/"+dealerid[i]+"/"+infoid[i]+".html")
    newresponse = requests.get(url1)
    print(url1)
    print(newresponse.status_code)
    newhtml = newresponse.text
    newehtml = etree.HTML(newhtml)
    price = newehtml.xpath("//span[@class='price']/text()")
    brand = newehtml.xpath("//h3[@class='car-brand-name']/text()")
    mileage = newehtml.xpath("//ul[@class='brand-unit-item fn-clear']/li[1]/h4/text()")
    outputandgear = newehtml.xpath("//ul[@class='brand-unit-item fn-clear']/li[3]/h4/text()")
    location = newehtml.xpath("//ul[@class='brand-unit-item fn-clear']/li[4]/h4/text()")
    insurance = newehtml.xpath("//div[@class='all-basic-content fn-clear']/ul[2]/li[2]/text()")
    seller1 = newehtml.xpath("//div[@class='rank-tag']/span[@class='num']/text()")
    seller2 = newehtml.xpath("//div[@class='rank-tag']/span[2]/text()")
    for i in range(len(price)):
        print(
            "价格:"+ price[i] +"万",
            "品牌:"+ brand[i],
            "里程数:"+ mileage[i],
            "排量与档位:"+ outputandgear[i],
            "所在地:"+location[i],
            "保险到期时间:"+insurance[i],
            "卖家:"+seller1[i]+seller2[i],
        )